/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidad de Almeria
 * License Type: Purchased
 */
package foroindaltronia.bd;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class Tema_no_terminal_visibleDAO {
	public static Tema_no_terminal_visible loadTema_no_terminal_visibleByORMID(int ID) throws PersistentException  {
		PersistentSession session = foroindaltronia.bd.ProyectoForoPersistentManager.instance().getSession();
		return loadTema_no_terminal_visibleByORMID(session, ID);
	}
	
	public static Tema_no_terminal_visible loadTema_no_terminal_visibleByORMID(PersistentSession session, int ID) throws PersistentException {
		return (Tema_no_terminal_visible) session.load(foroindaltronia.bd.Tema_no_terminal_visible.class, new Integer(ID));
	}
	
	public static Tema_no_terminal_visible[] listTema_no_terminal_visibleByQuery(String condition, String orderBy) throws PersistentException  {
		PersistentSession session = foroindaltronia.bd.ProyectoForoPersistentManager.instance().getSession();
		return listTema_no_terminal_visibleByQuery(session, condition, orderBy);
	}
	
	public static Tema_no_terminal_visible[] listTema_no_terminal_visibleByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From foroindaltronia.bd.Tema_no_terminal_visible as Tema_no_terminal_visible");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		Query query = session.createQuery(sb.toString());
		try {
			List list = query.list();
			return (Tema_no_terminal_visible[]) list.toArray(new Tema_no_terminal_visible[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Tema_no_terminal_visible loadTema_no_terminal_visibleByQuery(String condition, String orderBy) throws PersistentException {
		PersistentSession session = foroindaltronia.bd.ProyectoForoPersistentManager.instance().getSession();
		return loadTema_no_terminal_visibleByQuery(session, condition, orderBy);
	}
	
	public static Tema_no_terminal_visible loadTema_no_terminal_visibleByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tema_no_terminal_visible[] tema_no_terminal_visibles = listTema_no_terminal_visibleByQuery(session, condition, orderBy);
		if (tema_no_terminal_visibles != null && tema_no_terminal_visibles.length > 0)
			return tema_no_terminal_visibles[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTema_no_terminal_visibleByQuery(String condition, String orderBy) throws PersistentException  {
		PersistentSession session = foroindaltronia.bd.ProyectoForoPersistentManager.instance().getSession();
		return iterateTema_no_terminal_visibleByQuery(session, condition, orderBy);
	}
	
	public static java.util.Iterator iterateTema_no_terminal_visibleByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From foroindaltronia.bd.Tema_no_terminal_visible as Tema_no_terminal_visible");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		Query query = session.createQuery(sb.toString());
		try {
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Tema_no_terminal_visible createTema_no_terminal_visible() {
		return new foroindaltronia.bd.Tema_no_terminal_visible();
	}
	
	public static boolean save(foroindaltronia.bd.Tema_no_terminal_visible tema_no_terminal_visible) {
		try {
			foroindaltronia.bd.ProyectoForoPersistentManager.instance().saveObject(tema_no_terminal_visible);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean delete(foroindaltronia.bd.Tema_no_terminal_visible tema_no_terminal_visible) {
		try {
			foroindaltronia.bd.ProyectoForoPersistentManager.instance().deleteObject(tema_no_terminal_visible);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean deleteAndDissociate(foroindaltronia.bd.Tema_no_terminal_visible tema_no_terminal_visible) {
		try {
			if(tema_no_terminal_visible.getTema_no_terminal_visible_padre() != null) {
				tema_no_terminal_visible.getTema_no_terminal_visible_padre().los_subtemas.remove(tema_no_terminal_visible);
			}
			
			foroindaltronia.bd.Tema_no_terminal_visible[] lLos_subtemass = tema_no_terminal_visible.los_subtemas.toArray();
			for(int i = 0; i < lLos_subtemass.length; i++) {
				lLos_subtemass[i].setTema_no_terminal_visible_padre(null);
			}
			foroindaltronia.bd.Tema_terminal_visible[] lContiene_visibless = tema_no_terminal_visible.contiene_visibles.toArray();
			for(int i = 0; i < lContiene_visibless.length; i++) {
				lContiene_visibless[i].setEsta_en(null);
			}
			foroindaltronia.bd.Tema_no_terminal_oculto[] lContiene_ocultos = tema_no_terminal_visible.contiene_oculto.toArray();
			for(int i = 0; i < lContiene_ocultos.length; i++) {
				lContiene_ocultos[i].setEsta_en(null);
			}
			foroindaltronia.bd.Tema_teminal_oculto[] lContiene_ocultoss = tema_no_terminal_visible.contiene_ocultos.toArray();
			for(int i = 0; i < lContiene_ocultoss.length; i++) {
				lContiene_ocultoss[i].setEsta_en_2(null);
			}
			return delete(tema_no_terminal_visible);
		}
		catch(Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean deleteAndDissociate(foroindaltronia.bd.Tema_no_terminal_visible tema_no_terminal_visible, org.orm.PersistentSession session) {
		try {
			if(tema_no_terminal_visible.getTema_no_terminal_visible_padre() != null) {
				tema_no_terminal_visible.getTema_no_terminal_visible_padre().los_subtemas.remove(tema_no_terminal_visible);
			}
			
			foroindaltronia.bd.Tema_no_terminal_visible[] lLos_subtemass = tema_no_terminal_visible.los_subtemas.toArray();
			for(int i = 0; i < lLos_subtemass.length; i++) {
				lLos_subtemass[i].setTema_no_terminal_visible_padre(null);
			}
			foroindaltronia.bd.Tema_terminal_visible[] lContiene_visibless = tema_no_terminal_visible.contiene_visibles.toArray();
			for(int i = 0; i < lContiene_visibless.length; i++) {
				lContiene_visibless[i].setEsta_en(null);
			}
			foroindaltronia.bd.Tema_no_terminal_oculto[] lContiene_ocultos = tema_no_terminal_visible.contiene_oculto.toArray();
			for(int i = 0; i < lContiene_ocultos.length; i++) {
				lContiene_ocultos[i].setEsta_en(null);
			}
			foroindaltronia.bd.Tema_teminal_oculto[] lContiene_ocultoss = tema_no_terminal_visible.contiene_ocultos.toArray();
			for(int i = 0; i < lContiene_ocultoss.length; i++) {
				lContiene_ocultoss[i].setEsta_en_2(null);
			}
			try {
				session.delete(tema_no_terminal_visible);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean refresh(foroindaltronia.bd.Tema_no_terminal_visible tema_no_terminal_visible) {
		try {
			foroindaltronia.bd.ProyectoForoPersistentManager.instance().getSession().refresh(tema_no_terminal_visible);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static Tema_no_terminal_visible loadTema_no_terminal_visibleByCriteria(Tema_no_terminal_visibleCriteria tema_no_terminal_visibleCriteria) {
		Tema_no_terminal_visible[] tema_no_terminal_visibles = listTema_no_terminal_visibleByCriteria(tema_no_terminal_visibleCriteria);
		if(tema_no_terminal_visibles == null || tema_no_terminal_visibles.length == 0) {
			return null;
		}
		return tema_no_terminal_visibles[0];
	}
	
	public static Tema_no_terminal_visible[] listTema_no_terminal_visibleByCriteria(Tema_no_terminal_visibleCriteria tema_no_terminal_visibleCriteria) {
		return tema_no_terminal_visibleCriteria.listTema_no_terminal_visible();
	}
}
